<?php
require 'Model.php';
	class CxModel extends Model{
		function __Construct(){
			parent::__Construct();
			$this->mod = 'videotype';
		}
		function getList(){
			$sql = "select * from {$this->mod}";
		    $data = $this->conn->query($sql);
			return $data;
		}
		function add($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }
			  $user = array(
					'typename' => trim($data['typename']),  
					
			  	);
			  $keys = implode(',',array_keys($user));
			  $values = implode("','", array_values($user));
			  $sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
		}
		function getOneByID($id){
			$sql = "select * from {$this->mod} where tid=".$id;
		    $result = $this->conn->query($sql);
	      	return $result;
		}

		function update($data){
			$user = array(
					'typename' => trim($data['typename']),  
			  	);
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./Upload/',array('jpg','gif','png'));
  				$user['pic'] = $pic;
  				}
			  
			 		  
			 $sets = '';
			  foreach ($user as $key=>$val){
			        $sets.=$key."='".$val."',";
			    }
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			   
			    $sql="UPDATE {$this->mod} SET {$sets} where tid=".$data['id'];
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
		}
		function del($id){
			$sql = "delete from {$this->mod} where tid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}
	}
?>